
package com.hulk.hyena.framework.exception;

import javax.servlet.http.HttpServletResponse;

import com.hulk.hyena.framework.enums.ErrorCodeEnum;
import com.hulk.hyena.framework.model.ErrorCode;

import com.google.common.base.Throwables;

import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * MSG 消息异常类
 * </p>
 *
 * @author hulk
 */
@Slf4j
public class HyenaException extends ApiException {

    private static final long serialVersionUID = 1L;

    public HyenaException(int httpCode, String msg, Exception ex) {
        this(httpCode, msg);
        if (httpCode < HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            log.info("Info: MsgException Info {}", ex.getMessage());
        } else {
            log.warn("Warn: MsgException Warn {}", Throwables.getStackTraceAsString(ex));
        }

    }

    public HyenaException(int httpCode, String msg) {
        super(ErrorCode.builder().error(ErrorCodeEnum.MSG_EXCEPTION.name()).status(httpCode).msg(msg).build());
    }

}
